package cn.edu.hit.education.service;

import java.util.Arrays;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.hit.education.dao.UserMapper;
import cn.edu.hit.education.pojo.User;
import cn.edu.hit.education.shiro.UserRealm;

/**
 * 
* <p>Title: UserServiceImpl</p>  
* <p>Description: </p>  
* @author 罗成
* @date 2021年5月4日
 */
@Service
public class UserServiceImpl implements IUserService {
	@Autowired
	UserMapper userMapper;

	@Autowired
	DefaultSecurityManager securityManager;
	
	@Autowired
	UserRealm userRealm;

	public void login(String username, String password) {
		securityManager.setRealm(userRealm);
		SecurityUtils.setSecurityManager(securityManager);
		Subject subject = SecurityUtils.getSubject();
		UsernamePasswordToken token = new UsernamePasswordToken(username,password);
		subject.login(token);

	}

	@Override
	public User queryUserByUsername(String username) {
		User user = userMapper.queryUserByUsername(username);
		return user;
	}

}
